/**
 * $Id: LoginSuccessHandler.java 19 2011-06-11 04:06:06Z feigme $
 */
package com.iary.interfaces.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class LoginSuccessHandler implements AuthenticationSuccessHandler {

	private String adminSuccessUrl;
	private String onlineSuccessUrl;

	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		String targetUrl;
		String type = (String) request.getSession().getAttribute("type");
		if (type != null && type.equals("admin")) {
			targetUrl = adminSuccessUrl;
		} else {
			targetUrl = onlineSuccessUrl;
		}
		response.sendRedirect(request.getContextPath() + targetUrl);
	}

	public String getAdminSuccessUrl() {
		return adminSuccessUrl;
	}

	public void setAdminSuccessUrl(String adminSuccessUrl) {
		this.adminSuccessUrl = adminSuccessUrl;
	}

	public String getOnlineSuccessUrl() {
		return onlineSuccessUrl;
	}

	public void setOnlineSuccessUrl(String onlineSuccessUrl) {
		this.onlineSuccessUrl = onlineSuccessUrl;
	}

}
